<!--
 * @Author: your name
 * @Date: 2019-11-12 17:06:06
 * @LastEditTime: 2019-11-12 21:37:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \HBDemo\1112demo.html
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="shortcut icon" href="#" />
    <title>Document</title>
</head>

<body>


    <script>
        var findSubstring = function(s, words) {
            let arr = [];
            if (!s.length || !words.length) {
                return arr;
            }
            let strLen = words.join("").length;
            let flag = true;
            let qurStr = "";
            for (var i = 0; i <= (s.length) - strLen; i++) {
                qurStr = s.substr(i, strLen);
                console.log(qurStr)
                for (let j = 0; j < words.length; j++) {
                    let n = qurStr.indexOf(words[j]);
                    if (n < 0) {
                        flag = false;
                        break;
                    }
                    qurStr = qurStr.replace(qurStr.substr(n, words[j].length), "");
                    flag = true;
                }
                if (flag) {
                    arr.push(i);
                }
            }
            return arr;

        };

        console.log(findSubstring("ababaab", ["ab", "ba", "ba"]));
    </script>
</body>

</html>